package com.qsl.ssyx.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qsl.ssyx.model.product.Category;
import com.qsl.ssyx.product.mapper.CategoryMapper;
import com.qsl.ssyx.product.service.CategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qsl.ssyx.vo.product.CategoryQueryVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 商品三级分类 服务实现类
 * </p>
 *
 * @author 青衫泪
 * @since 2023-08-11
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    //    条件分页查询
    @Override
    public IPage<Category> selectPage(Page<Category> pageParam, CategoryQueryVo categoryQueryVo) {
        LambdaQueryWrapper<Category> lqw = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(categoryQueryVo.getName())) {
            lqw.like(Category::getName, categoryQueryVo.getName());
        }

        lqw.orderByDesc(Category::getId);// 倒序排序

        Page<Category> categoryPage = baseMapper.selectPage(pageParam, lqw);
        return categoryPage;
    }
}
